package org.example.mytest;

/**
 * @author: 默苍璃
 * @date: 2023-02-13 17:11
 * 测试 线程中断
 */
public class Test01 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new MyThread();
        t.start();

        // 暂停1毫秒 暂停的是主线程
        Thread.sleep(1);

        t.interrupt(); // 中断t线程
        t.join(); // 等待t线程结束

        System.out.println("end");
    }
}

class MyThread extends Thread {
    public void run() {
        int n = 0;
        while (!isInterrupted()) {
            n++;
            System.out.println(n + " hello!");
        }
    }
}

